var fs = require('fs');
var path = require('path');
var DxfStruct = require('./DxfStruct2');
var DxfParser = require('../');

var DXF_FILE_PATH = path.join(__dirname, 'data', 'sy.dxf');
var OUTPUT_FILE_NAME = "cad.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });
var parser = new DxfParser();
var layer_color = {}

parser.parseStream(fileStream, function (err, dxf) {
    if (err) return console.error(err.stack);
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));
    dxf.sys = { start: 371, points: [], dn: 400 }
    dxfstruct = new DxfStruct(dxf)
    var blocks = ['gc304', 'gc178', 'gc214', 'GC026', 'gc104', 'GC101', 'GC021', 'GC023', 'GC020', 'gc309', 'GC030',
        'gc022', 'GC103', 'gc019', 'gc029', 'bc128', 'gc302', 'gc075', 'gc310', 'gc203', 'GC105',
        'gc106', '47.00-99.00', '*D91', 'DLSS', 'JMD', 'SXSS', '给水']
    var layers = ['0', 'JMD']//'DLSS','JMD','SXSS','给水内业点号','给水线注记'
    var merge = ['DLSS', 'JMD', 'SXSS']

    var newLayer = {
        layer: ['0', '4321', '4421', '4331', '4330', '2110', '注记', '路名', 'Road', '000_住宅'],
        hatch: ['0'],
        blocks: false,
        text: {
            '0': '标识标注',
        },
        new: {
            '4421': 'Road'
        },
        clayer: {
            '0': {
                '5814856': 'DN80',
                '1284936': 'DN100',
                '13461800': 'DN150',
                '10033950': 'DN200',
                '2699657': 'DN300',
                '1070729': 'DN300',

                '16711935': '标注线',
                '65280': '源水',
                '65535': '规划供水管',

                '16711680': '支线',
            }
        },
        tlayers: {
            '标识标注': { c: '11382189', b: false },
            '4321': { c: '11382189', b: false },
            '4331': { c: '11382189', b: false },
            '4330': { c: '11382189', b: false },
            '2110': { c: '11382189', b: false },
            '注记': { c: '11382189', b: false },
            'Road': { c: '11382189', b: false },
            '000_住宅': { c: '11382189', b: false },
            '路名': { c: '11382189', b: false },

            '0': { c: '16711680', b: false },
            '标注线': { c: '16711935', b: false },
            '源水': { c: '65280', b: false },
            '规划供水管': { c: '65535', b: false },
            '支线': { c: '16711680', b: false },


            'DN80': { c: '5814856', b: true },
            'DN100': { c: '1284936', b: true },
            'DN150': { c: '13461800', b: true },
            'DN200': { c: '10033950', b: true },
            'DN300': { c: '1070729', b: true },
        },
        //'4321','2110','注记'
        merge: ['DN400', '标注线', '源水', '4321', '4331', '4330', '2110', '支线', 'Road', '000_住宅']
    }
    dxfstruct.setShowLayers(newLayer)
    dxfstruct.resetDxf('user')

    console.log('dxfstruct', dxfstruct.dxf.entities.length)
    fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf));
    //console.log(dxfstruct.getDxfStruct())
});